<template>
    <div>
        <table class="table">
            <tbody class="table">
                <tr>
                    <td>房号编号</td>
                    <td>
                        <input type="text" v-model="data.houseNum" >
                    </td>
                </tr>
                <tr>
                    <td>名称</td>
                    <td>
                        <input type="text" v-model="data.houseName">
                    </td>
                </tr>
                <tr>
                    <td>地址</td>
                    <td>
                        <input type="text" v-model="data.address">
                    </td>
                </tr>
                <tr>
                    <td></td>
                    <td colspan="2">
                        <input type="button" value="修改" @click="add">
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import { ref,onMounted } from 'vue';
import { useRoute, useRouter } from 'vue-router';
onMounted(() => {
    backdata();
})

const route=useRoute();
const backdata=()=>{
    var n=route.query.id;
    axios.get("https://localhost:7233/api/House/GetHouse",{params:{id:n}}).then(res=>{
        data.value=res.data;
    })
}

const data=ref({
    "hid": 0,
  "houseNum": "",
  "houseName": "",
  "address": ""
})




const router=useRouter();
const add=()=>{
    axios.put("https://localhost:7233/api/House/UpdateHouse",data.value).then(res=>{
        if(res.data>0){
            alert("修改成功");
            router.push({
                path:'/ShowView'
            })
        }else{
            alert("修改失败")
        }
    })
}


</script>

<style scoped>

</style>